/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;


import java.security.*;

public class MD5 {

    public String stringToMD5(String s) {
        String returnData = "";
        
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.reset();
            md.update(s.getBytes());
            
            byte[] encode = md.digest();
            String tmp ="";
            for(int i=0;i<encode.length;i++) {
                tmp = (Integer.toHexString(0xFF & encode[i]));
                if(tmp.length() == 1) {
                    returnData += "0"+tmp;
                } else {
                    returnData += tmp;
                }
            }
            
        } catch(Exception ex) {
            ex.printStackTrace();
            returnData = "ERROR";
        }
        
        return returnData;
    }
}
